/*
 * @Author: your name
 * @Date: 2021-02-01 15:23:40
 * @LastEditTime: 2021-02-04 17:36:57
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wwwd:\凯哥购物项目\pages\search\index.js
 */
// pages/search/index.js
import { request } from "../../request/index";

Page({
    data: {
        goods: [],
        isFocus: false,
        inpValue: ""
    },
    TimeId: -1,
    onShow: function() {

    },


    handlebindInput(e) {
        const { value } = e.detail;
        if (!value.trim()) {
            this.setData({
                goods: [],
                isFocus: false
            })
            return;
        }
        this.setData({
            isFocus: true
        });
        clearTimeout(this.TimeId);
        this.TimeId = setTimeout(() => {
            this.qsearch(value);
        }, 1000);
    },

    async qsearch(query) {
        const res = await request({ url:"/search/"+query+"/"});
        console.log(res);
        this.setData({
            goods: res
        })
    },

    handleCancel() {
        this.setData({
            goods: [],
            isFocus: false,
            inpValue: ""
        })
    },
})